<?php
class easyForm extends ajaxForm
{
    function easyForm($id=NULL, $inner=NULL, $action='index.php', $method='post', $onSubmit=NULL, $class=NULL)
    {
        parent::ajaxform($id, $inner, $action, $method, $onSubmit, $class);
    }

    function __toString()
    {
        $class      = $this->class;
        $styles     = $this->getStyle();
        $this       ->removeAttribute('class');
        $this       ->removeAttribute('labelWidth');
        $id         = $this->id;
        $elements   = $this->getInnerHTML();

        if (count($elements)>1)
        {
            foreach ($elements as $line =>$info)
            {
                if (is_object($info))
                {
                    if (! $elements[$line]->class )
                    {
                        $elements[$line]->class = strtolower(get_class($info) );
                    }
                }
                $tr[]       = new tr(null,$this->sub__toString($info));
            }
            $table  = new htmlTable("table$id", $tr, $class);
            $table  ->setStyles($styles);
            $this   ->setInnerHTML($table);
        }
        return parent::__toString();
    }

    function sub__toString($info)
    {
        if (is_array($info) )
        {
            foreach ($info as $l => $d)
            {
            	$l = $l;
                $result .= $this->sub__toString($d);
            }
        }
        else if (is_object($info) )
        {
            if ( $info->label )
            {
                $tdLabel    = new td(null, new Label(null, $info->label, $info->id) , 'label');
                //$tdLabel    ->add('width', $labelWidth);
            }
            $id = $info->id;
            if ($id)
            {
            	$id = '_'.$id;
            }
            $tdElement  = new td( $id , $info  );
            if (!$tdLabel)
            {
                $tdElement->colspan = '2';
            }
            $result .= $tdLabel. $tdElement ;
        }
        return $result;
    }

    /*fsunction setLabelWidth($width)
    {
        $this->add('labelWidth', $width);
    }*/
}

function isAjaxFunction($function)
{
    return ($_REQUEST['ajax'] == 'true' && ($_REQUEST['phpFunction']==$function));
}
?>